<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>四则运算</title>
</head>

<body>
    <h1>简易的四则运算:</h1>
    <script>
        var num1 = parseFloat(prompt("请输入第一个数字:"));
        var operator = prompt("请选择运算符号：+ (加法), - (减法), * (乘法), / (除法)");
        var num2 = parseFloat(prompt("请输入第二个数字:"));

        var result;
        switch (operator) {
            case '+':
                result = num1 + num2;
                document.write(num1 + " + " + num2 + " = " + result);
                break;
            case '-':
                result = num1 - num2;
                document.write(num1 + " - " + num2 + " = " + result);
                break;
            case '*':
                result = num1 * num2;
                document.write(num1 + " * " + num2 + " = " + result);
                break;
            case '/':
                if (num2 !== 0) {
                    result = num1 / num2;
                    document.write(num1 + " / " + num2 + " = " + result);
                } else {
                    document.write("除数不能为0");
                }
                break;
            default:
                document.write("无效的运算符号");
        }
    </script>
</body>

</html>